import { http } from '@/utils/http/axios';
import axios from 'axios';
import { useUser } from '@/store/modules/user';

/**
 * @description: 模型列表
 */
export function modelDesignPage(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/page',
    method: 'POST',
    data: params,
  });
}

/**
 * @description: 保存模型
 */
export function saveModelDesign(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/saveModelDesign',
    method: 'POST',
    data: params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * @description: 修改模型
 */
export function updateModelDesign(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/updateModelDesign',
    method: 'POST',
    data: params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * @description: 删除模型
 */
export function removeModelDesign(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/removeModelDesign',
    method: 'POST',
    data: params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * @description: 模型默认字段
 */
export function defaultField(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDefaultField/defaultField',
    method: 'POST',
    data: params,
  });
}

/**
 * @description: 模型详情
 */
export function modeDetail(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/modeDetail',
    method: 'POST',
    data: params,
  });
}

/**
 * @description: 获取SQL脚本
 */
export function getSqlScript(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/getSqlScript',
    method: 'POST',
    data: params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * @description: 同步数据源
 */
export function syncDataSource(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/syncDataSource',
    method: 'POST',
    data: params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * @description: 撤回同步
 */
export function recallSync(params) {
  return http.request({
    url: '/moss-cloud-plugins/plugins/modelDesign/recallSync',
    method: 'POST',
    data: params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * @description: 生成代码
 */
export function generateCode(params) {
  const userStore = useUser();
  const token = 'Bearer ' + userStore.getToken;
  return axios.post('/moss-cloud-plugins/plugins/modelDesign/generateCode', params,
    { responseType: 'blob',headers: { 'Authorization': token }});
}

/**
 * @description: 生成项目模板
 */
export function genProject(params) {
  const userStore = useUser();
  const token = 'Bearer ' + userStore.getToken;
  return axios.post('/moss-cloud-plugins/plugins/modelDesign/genProject', params,
    { responseType: 'blob',headers: { 'Authorization': token }});
}